#pragma once

#include <QTcpServer>
#include "Client.h"
#include "Protocol.h"

typedef QHash<QString, Client*> OnlineUsers;

// 服务器
class Server: public QTcpServer {
    Q_OBJECT

    friend class Client;

    private: OnlineUsers mOnlineUsers;  // 在线用户列表

    public: explicit Server();
    public: ~Server();
    public: void handleFindUsers(FindUsersRequest*, Client*);
    public: void handleProtocol(GomokuProtocol*);
    public: void handleLogon(LogonRequest*, Client*);
    public: void handleQuitGame(QuitGame*, Client*);
    private slots: void onAccept();
    public: void onGetMessageFromClient(GomokuProtocol*, Client*);
    private: void sendData(Client*, GomokuProtocol*, qint64);
    public: bool start();
};
